<template>
	<el-container>
		<el-main class="nopadding">
			<el-header style="height: auto;">
				<sc-select-filter :data="filterData" :label-width="80" @on-change="filterChange"></sc-select-filter>
			</el-header>
			<el-header>
				<el-form-item label="人员部门">
					<select-hr-dept-dialog v-model:deptId="search.deptId" :mode="false"/>
				</el-form-item>
			</el-header>
			<el-main>
				<el-row :gutter="15">
					<el-col :lg="16" :offset="4">
						<el-card shadow="never" v-if="this.search.echartType!='3'">
							<scEcharts height="300px" :option="option"></scEcharts>
						</el-card>
						<scTable ref="table" :data="tableData" row-key="id" stripe v-if="this.search.echartType=='3'">
							<el-table-column label="#" type="index" width="50"></el-table-column>
							<el-table-column label="名称" prop="name" width="150"></el-table-column>
							<el-table-column label="数值" prop="value"></el-table-column>
						</scTable>
					</el-col>
				</el-row>
			</el-main>
		</el-main>
	</el-container>
</template>

<script>
import scSelectFilter from '@/components/scSelectFilter'
import selectHrDeptDialog from "@/views/module/selectHrDeptDialog";
import scEcharts from '@/components/scEcharts';
export default {
	name: 'My BaseInfo BI Manage',
	components: {
		scSelectFilter,
		scEcharts,
		selectHrDeptDialog
	},
	data() {
		return {
			dialog: {
				detailsSave: false,
			},
			tableData:[],
			option: {},
			filterData: [
				{
					title: "数据类型",
					key: "dataType",
					multiple: false,
					options: [
						{
							label: "关怀类型",
							value: "1"
						}
					]
				},
				{
					title: "展示方式",
					key: "echartType",
					multiple: false,
					options: [{
						label: "饼状图",
						value: "1"
					},
						{
							label: "柱状图",
							value: "2"
						},
						{
							label: "明细表",
							value: "3"
						}]
				}
			],
			search: {
				dataType: '1',
				echartType: '1',
				deptId: null,
			}
		}
	},
	watch: {
		'search.deptId': {
			handler(val) {
				this.search.deptId = val;
				this.getValue();
			}
		}
	},
	mounted() {
		this.getValue();
	},
	methods: {
		getValue()
		{
			if(this.search.echartType=="1")
			{
				this.getCarePieForAnalysis();
			}else if(this.search.echartType=="2")
			{
				this.getCareBarForAnalysis();
			}else if(this.search.echartType=="3")
			{
				this.getCareTableForAnalysis();
			}
		},
		filterChange(data) {
			this.search.dataType = data.dataType;
			this.search.echartType = data.echartType;
			this.search.deptId = data.deptId;
			this.getValue();
		},
		async getCarePieForAnalysis() {
			var res = await this.$API.hr.echarts.getCarePieForAnalysis.get(this.search);
			if (res.code == 200) {
				this.option = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getCareBarForAnalysis(){
			var res = await this.$API.hr.echarts.getCareBarForAnalysis.get(this.search);
			if (res.code == 200) {
				this.option = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		async getCareTableForAnalysis()
		{
			var res = await this.$API.hr.echarts.getCareTableForAnalysis.get(this.search);
			if (res.code == 200) {
				this.tableData = res.data;
			} else {
				this.$alert(res.message, "提示", {type: 'error'})
			}
		},
		//本地更新数据
		handleSaveSuccess() {
		}
	}
}
</script>

<style>
</style>
